package com.qfedu.edu.seckill.encoder;

import com.qfedu.edu.seckill.utils.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class MyPasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(CharSequence charSequence) {
        return MD5.encrypt(charSequence.toString());
    }

    /**
     *
     * @param charSequence：前端传递过来的密码(未散列的)
     * @param sqlPassword(从数据库查询出来的密码散列了的)
     * @return
     */
    @Override
    public boolean matches(CharSequence charSequence, String sqlPassword) {
        return encode(charSequence.toString()).equals(sqlPassword);
    }
}
